/**
 * Created by Administrator on 2017/2/28 0028.
 */


import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Navigator,
    BackAndroid
} from 'react-native';

//var Login = require('./../else/login');
//var Register = require('./../else/register');
//var forgetP = require('./../else/forgetP');
//var confirmP = require('./../else/confirmP');
import Login from './../else/login';
import Register from './../else/register';
import ForgetP from './../else/forgetP';
import ConfirmP from './../else/confirmP';
import HistoryDetails from './../else/historyDetails';
import HistoryOrder from './../else/historyOrder';
import nowOrderH from './../else/nowOrderH';

var DefaultView = React.createClass({
    render(){
        return (
            <View >
                <Text>Default view</Text>
            </View>
        )
    }
});

export default class NaviModule extends Component{

    configureScene(route){
        return Navigator.SceneConfigs.FadeAndroid;
    }

    renderScene(route, navigator){
        var Component = null;this._navigator = navigator;
        switch (route.name){
            case "login":
                Component = Login;
                break;
            case "register":
                Component = Register;
                break;
            case "forgetP":
                Component = ForgetP;
                break;
            case "confirmP":
                Component = ConfirmP;
                break;
            case "historyDetails":
                Component = HistoryDetails;
                break;
            case "historyOrder":
                Component = HistoryOrder;
                break;
            case "nowOrderH":
                Component = nowOrderH;
                break;
            default: //default view
                Component = DefaultView;
        }

        return <Component navigator={navigator} />
    }

    componentDidMount() {
        var navigator = this._navigator;
        BackAndroid.addEventListener('hardwareBackPress', function() {
            if (navigator && navigator.getCurrentRoutes().length > 1) {
                navigator.pop();
                return true;
            }
            return false;
        });
    }


    componentWillUnmount() {
        BackAndroid.removeEventListener('hardwareBackPress');
    }

    render() {
        return (
            <Navigator
                initialRoute={{name: 'nowOrderH'}}
                configureScene={this.configureScene}
                renderScene={this.renderScene} />
        );
    }

}


AppRegistry.registerComponent('NaviModule', () => NaviModule);
